<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/10 0010
 * Time: 下午 1:47
 */

namespace app\common\model;

use app\admin\validate\Config;
use think\Loader;
use think\Model;

class Common extends Model
{
    public function store($data, $valname=null)
    {
        $validate = Loader::validate($valname);
        if($validate->check($data)) {
            //模型的更新和新增
            if(isset($data[$this->pk])){
                $res = $this->isUpdate()->save($data);
            }else{
                $res = $this->insertGetId($data);
            }
            return ['status'=>'success','data'=>$res,'msg'=>'操作成功'];
        }else{
            return ['status'=>'error','msg'=>$validate->getError()];
        }
    }
}